<?php
require_once MODEL_PATH.DS.'Product.php';
require_once MODEL_PATH.DS.'ProductDesc.php';
require_once MODEL_PATH.DS.'Category.php';
$Product = new Product();
$Category = new Category();
$ProductDesc = new ProductDesc();
$category_id = isset($_GET['cate_id'])?(int)$_GET['cate_id']:'';
$page = isset($_GET['page'])?(int)$_GET['page']:1;
$limit = 12;
$offset = $page * $limit - $limit;

if(!empty($category_id)){
	$product_arr = $Product->getProductsByCategoryId($category_id);
	$product_ids = get_array($product_arr,'product_id','string');
	//dump($product_ids);
	if($product_ids){
		$product_list = $Product->getProductInfoInPIds($product_ids,$offset,$limit);
		$nums = $Product->countProductsByCategoryId($category_id);
	}
}else{
	$product_list = $Product->getAllProductList($offset,$limit);
	$nums = $Product->countProducts();
}

$url   = get_page_url();
$pages = get_pagehtml($num, $limit, $page, $url);


$cat_list = $Category->getAllCategories();
$tpl->assign('cat_list',$cat_list);
$tpl->assign('product_list',$product_list);
$tpl->assign('pages',$pages);
$tpl->display('product_index.tpl');
?>